package sw;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import sw.entity.Books;
import sw.entity.Classes;
import sw.repo.BooksRepository;
import sw.repo.ClassesRepository;

@SpringBootApplication
public class Application {

	@Autowired
	private BooksRepository booksRepo;
	@Autowired
	private ClassesRepository clasRepo;
	
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

  //用于初始化数据库数据，防止应用程序每次启动都没有数据
    @Bean
	public CommandLineRunner demo() {
		return (args) -> {
			Books book1 = new Books(1L,"在时光中盛开的女子","李筱懿","上海文艺出版社","111");
			Books book2 = new Books(2L,"打火机与公主裙 ","Twentine","青岛出版社","222");
			booksRepo.save(book1);
			booksRepo.save(book2);
			
			Classes clas1 =new Classes(1L,"英语");
			Classes clas2 =new Classes(2L,"计算机");
			clasRepo.save(clas1);
			clasRepo.save(clas2);
			
		};
    }
}
